package com.zxx.pattern.statePattern.state;

/**
 * 没有糖果的状态
 *
 * @author zxx on 2021/1/14
 */
public class StateNoCandy implements State {

    private CandyMachine candyMachine;

    public StateNoCandy(CandyMachine candyMachine) {
        this.candyMachine = candyMachine;
    }

    @Override
    public void onMoneyInserted() {
        System.out.println("已经没有糖果了！");
        onMoneyReturned();
    }

    @Override
    public void onMoneyReturned() {
        System.out.println("投币退回！");
        //投币退回，并设置为最初状态（StateNoMoney--没有投币的状态）
        candyMachine.setState(candyMachine.getNoMoneyState());
    }

    @Override
    public void onCrankTurned() {
        System.out.println("已经没有糖果了！操作无效");
        onMoneyReturned();
    }

    @Override
    public void onCandyPoped() {
        System.out.println("已经没有糖果了！");
        onMoneyReturned();
    }
}
